package com.itheima.mapdemo.treemapstudent;

import java.util.Comparator;
import java.util.TreeMap;

public class Test {
    public static void main(String[] args) {
        TreeMap<Student, String> tm = new TreeMap<>(new Comparator<Student>() {
            //匿名内部类,重写compare方法
            @Override
            public int compare(Student o1, Student o2) {
                int result = o1.getAge()-o2.getAge();
              result =  result ==0 ? o1.getName().compareTo(o2.getName()) : result;
                return result;
            }
        });
        Student s1 = new Student("张三", 18);
        Student s2 = new Student("张三1", 16);
        Student s3 = new Student("张三2", 16);

        tm.put(s1,"江苏");
        tm.put(s2,"北京");
        tm.put(s3,"深圳");

        tm.forEach(
                (key,value) -> {
                    System.out.println(key + "--" + value);
                }
        );
    }
}
